package month4.day27;

import java.io.*;

public class S5 {
    public static void main(String[] args) {
        //获得文件行数的方法
        // 有 bufferedReader.readLine 方法 或者查找byte是否=='\n',比较谁快！
        File file = new File("E:\\Java8\\新建文件夹\\java78.txt");
        BufferedReader a;
        InputStream b;
        try {
            a = new BufferedReader(new FileReader(file));
            b = new FileInputStream(file);
            int n = 0;
            long time = System.nanoTime();
            while (a.readLine() != null) {
                n++;
            }
            System.out.println(n + "行");
            long time1 = System.nanoTime();
            System.out.println(time1 - time);

            byte[] by = new byte[1];
            n = 0;
            long time2 = System.nanoTime();
            while ((b.read(by)) != -1) {
                for (byte value : by) {
                    int v = value & 0xFF;
                    String hv = Integer.toHexString(v);
                    if (hv.length() < 2) {
                        hv = "0" + hv;
                    }
                    if (hv.equals("0a")) {
                        n++;
                    }
                }
            }
            System.out.println(n + "行");
            long time3 = System.nanoTime();
            System.out.println(time3 - time2);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
